﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IntelligentCMS
{
    public partial class CMSRadioButton : System.Web.UI.UserControl, iCMSControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #region iCMSControl Members

        private bool checkforerrors = false;
        private string name = string.Empty;

        public string Name
        {
            set
            {
                name = value;
            }
        }

        private List<string> errorlist()
        {
            List<string> errorlist = new List<string>();

            if (theRadioButtonList.SelectedValue == string.Empty && checkforerrors)
            {
                errorlist.Add(name + strings.fielderror);
            }
            return errorlist;
        }

        private bool haserrors()
        {
            if (errorlist().Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }

        }

        public List<string> Choices
        {
            set
            {
                theRadioButtonList.DataSource = value; theRadioButtonList.DataBind();
            }

        }


        public System.Web.UI.WebControls.Unit InternalWidth
        {
            set
            {
                //theTextBox.Width = value;
            }
        }

        public System.Web.UI.WebControls.Unit InternalHeight
        {
            set
            {
                //theTextBox.Height = value;
            }
        }

        private string generatesqlstring()
        {
            string sqlstring = string.Empty;

            sqlstring += "INSERT INTO [" + strings.databaseprefix + "].[dbo].[" + strings.databaseprefix + "_RadioButton] ([Name], [Value], [URL], [Time]) VALUES ('" + common.GetBase64String(name) + "','" + common.GetBase64String(theRadioButtonList.SelectedIndex.ToString()) + "','" + common.GetBase64String(clienturl) + "', GETDATE());";
            //sqlstring += "INSERT INTO [" + strings.databaseprefix + "].[dbo].[" + strings.databaseprefix + "_RadioButton] ([Name], [Value], [URL], [Time]) VALUES ('" + name + "','" + theRadioButtonList.SelectedIndex.ToString() + "','" + clienturl + "', GETDATE());";

            return sqlstring;

        }


        private string clienturl = string.Empty;

        public string ClientURL
        {
            set
            {
                clienturl = value;
            }


        }

        public List<string> Errors
        {
            get { return errorlist(); }
        }

        public string SQLString
        {
            get { return generatesqlstring(); }
        }

        public string LabelText
        {
            set { theLabel.Text = value; }
        }

        public bool CheckForErrors
        {
            set { checkforerrors = value; }
        }

        public bool HasErrors
        {
            get { return haserrors(); }
        }


        #endregion
    }
}